﻿<!DOCTYPE>
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
        <title>选址分区分析</title>
        <style type="text/css">
            body{
                margin: 0;
                overflow: hidden;
                background: #fff;
            }
            #map{
                position: relative;
                height: 510px;
                border:1px solid #3473b7;
            }
            #toolbar {
                position: relative;
                padding-top: 5px;
                padding-bottom: 10px;
            }
        </style>
        <link href='./css/bootstrap.min.css' rel='stylesheet' />
        <link href='./css/bootstrap-responsive.min.css' rel='stylesheet' />
        <script src='../libs/SuperMap.Include.js'></script>
        <script type="text/javascript">
            var host = document.location.toString().match(/file:\/\//)?"http://localhost:8090":'http://' + document.location.host;
            var local, map, layer, vectorLayer, markerLayer1,
            markerLayer2,
            style = {
                strokeColor: "#304DBE",
                strokeWidth: 2,
                pointRadius: 2,
                pointerEvents: "visiblePainted",
                fill: true,
                fillColor: "#304DBE"
            },
            url1=host+"/iserver/services/map-changchun/rest/maps/长春市区图",
            url2=host+"/iserver/services/transportationanalyst-sample/rest/networkanalyst/RoadNet@Changchun";
            function init(){
                map = new SuperMap.Map("map",{controls: [
                    new SuperMap.Control.LayerSwitcher(),
                    new SuperMap.Control.ScaleLine(),
                    new SuperMap.Control.Zoom(),
                    new SuperMap.Control.Navigation({
                        dragPanOptions: {
                            enableKinetic: true
                        }
                    })], units: "m"
                });
                layer = new SuperMap.Layer.TiledDynamicRESTLayer("Changchun",url1, {transparent: true, cacheEnabled: true},{maxResolution:"auto"});
                layer.events.on({"layerInitialized":addLayer});
                vectorLayer = new SuperMap.Layer.Vector("Vector Layer");
                markerLayer1 = new SuperMap.Layer.Markers("Markers");
                markerLayer2 = new SuperMap.Layer.Markers("Markers");
                var size = new SuperMap.Size(44,40),
                        offset = new SuperMap.Pixel(-(size.w/2), -size.h);
                markerLayer1.addMarker(new SuperMap.Marker(new SuperMap.LonLat(1675.9256791377206, -593.56822512495194), new SuperMap.Icon("../theme/images/marker-gold.png", size, offset)));
                markerLayer1.addMarker(new SuperMap.Marker(new SuperMap.LonLat(2820.35101097629, -2358.0414663985171), new SuperMap.Icon("../theme/images/marker-gold.png", size, offset)));
                markerLayer1.addMarker(new SuperMap.Marker(new SuperMap.LonLat(2909.4396668115278, -3647.0074300836109), new SuperMap.Icon("../theme/images/marker-gold.png", size, offset)));
                markerLayer1.addMarker(new SuperMap.Marker(new SuperMap.LonLat(1544.5037476378677 ,-5616.5950974905827), new SuperMap.Icon("../theme/images/marker-gold.png", size, offset)));
                markerLayer1.addMarker(new SuperMap.Marker(new SuperMap.LonLat(6623.5972101719526, -2130.4887600981415), new SuperMap.Icon("../theme/images/marker-gold.png", size, offset)));
                markerLayer1.addMarker(new SuperMap.Marker(new SuperMap.LonLat(5482.4979617984973 ,-4504.2328567816048), new SuperMap.Icon("../theme/images/marker-gold.png", size, offset)));
                markerLayer1.addMarker(new SuperMap.Marker(new SuperMap.LonLat(6940.6579024271468 ,-1627.6012900626256), new SuperMap.Icon("../theme/images/marker-gold.png", size, offset)));
                markerLayer1.addMarker(new SuperMap.Marker(new SuperMap.LonLat(8215.9188781715948 ,-5747.5063918659716), new SuperMap.Icon("../theme/images/marker-gold.png", size, offset)));
            }

            function addLayer() {
                map.addLayers([layer, vectorLayer, markerLayer1, markerLayer2]);
                map.setCenter(new SuperMap.LonLat(4503.6240321526, -3861.911472192499), 0);
            }
            function findLocaltion() {
                vectorLayer.removeAllFeatures();
                markerLayer2.clearMarkers();

                var findLocaltionService, parameter, analystParameter, resultSetting,
                        supplyCenterType_FIXEDCENTER = SuperMap.REST.SupplyCenterType.FIXEDCENTER,
                        supplyCenterType_NULL = SuperMap.REST.SupplyCenterType.NULL;
                supplyCenterType_OPTIONALCENTER = SuperMap.REST.SupplyCenterType.OPTIONALCENTER,
                        supplyCenters=[new SuperMap.REST.SupplyCenter({
                            maxWeight: 500,
                            nodeID: 139,
                            resourceValue: 100,
                            type: supplyCenterType_OPTIONALCENTER

                        }),
                            new SuperMap.REST.SupplyCenter({
                                maxWeight: 500,
                                nodeID: 1358,
                                resourceValue: 100,
                                type: supplyCenterType_OPTIONALCENTER

                            }),
                            new SuperMap.REST.SupplyCenter({
                                maxWeight: 500,
                                nodeID: 2972,
                                resourceValue: 100,
                                type: supplyCenterType_OPTIONALCENTER

                            }),
                            new SuperMap.REST.SupplyCenter({
                                maxWeight: 500,
                                nodeID: 5523,
                                resourceValue: 100,
                                type: supplyCenterType_OPTIONALCENTER

                            }),
                            new SuperMap.REST.SupplyCenter({
                                maxWeight: 500,
                                nodeID: 1161,
                                resourceValue: 100,
                                type: supplyCenterType_OPTIONALCENTER
                            }),
                            new SuperMap.REST.SupplyCenter({
                                maxWeight: 500,
                                nodeID: 4337,
                                resourceValue: 100,
                                type: supplyCenterType_OPTIONALCENTER

                            }),
                            new SuperMap.REST.SupplyCenter({
                                maxWeight: 500,
                                nodeID: 5732,
                                resourceValue: 100,
                                type: supplyCenterType_NULL

                            }),
                            new SuperMap.REST.SupplyCenter({
                                maxWeight: 500,
                                nodeID: 663,
                                resourceValue: 100,
                                type: supplyCenterType_FIXEDCENTER

                            })
                        ];
                parameter = new SuperMap.REST.FindLocationParameters({
                    expectedSupplyCenterCount: 3,
                    isFromCenter: false,
                    nodeDemandField: "Demand",
                    turnWeightField: "TurnCost",
                    weightName: "length",
                    supplyCenters: supplyCenters
                });

                findLocaltionService = new SuperMap.REST.FindLocationService(url2, {
                    eventListeners: {"processCompleted": processCompleted}});
                findLocaltionService.processAsync(parameter);
            }

            function processCompleted(findLocationEventArgs) {
                var result = findLocationEventArgs.result,
                        features = [];
                if (result.demandResults){
                    for (var i=0,demandResults=result.demandResults,len=demandResults.length; i<len; i++) {
                        var feature = new SuperMap.Feature.Vector();
                        feature.geometry = demandResults[i].geometry;
                        feature.style = style;
                        features.push(feature);
                    }
                }
                vectorLayer.addFeatures(features);
            }

            function clearElements() {
                vectorLayer.removeAllFeatures();
                markerLayer2.clearMarkers();
            }
        </script>
    </head>
    <body onload="init()">
        <div id="toolbar">
            <input type="button" value="分析" class="btn" onclick="findLocaltion()" />
            <input type="button" value="清除" class="btn" onclick="clearElements()" />
        </div>
        <div id="map"></div>
    </body>
</html>
